const Utils = {
  //函数防抖
  //只有一定的时间间隔才触发，否则清空重置
  debounce: function(f, time = 200) {
    let timeout = null;
    return () => {
      clearTimeout(timeout);
      timeout = setTimeout(() => { f(); }, time);
    };
  },
  //函数节流
  //一定时间内只执行一
  throttle: function(func, time = 50) {
    let timeout = null;
    let startTime = new Date();
    return (...args) => {
      clearTimeout(timeout);
      let curTime = new Date();
      if (curTime - startTime < time) {
        timeout = setTimeout(() => {
          func.apply(null, args);
        }, time);
      } else {
        startTime = curTime;
        func.apply(null, args);
        // func();
      }
    };
  }
};